﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <fieldset class="table-search-fieldset layui-hide" id="searchField">
                @*<legend>搜索信息</legend>*@
                <div>
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label required">日期:</label>
                                <div class="layui-input-block">
                                    <input type="text" id="time_horizon" name="time_horizon" lay-verify="required" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label required">盘点类型:</label>
                                <div class="layui-input-block">
                                    <select id="checktype" name="checktype" lay-verify="required">
                                        <option value="0">库存盘点</option>
                                        <option value="1">质检盘点</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">关键字:</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>

            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container" id="toolbar">
                    <button id="NF-add" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="add"><i class="layui-icon">&#xe640;</i>清空记录</button>
                </div>
            </script>
            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        </div>
    </div>
    <script>
        layui.use(['jquery', 'form', 'laydate', 'table', 'common', 'optimizeSelectOption', 'commonTable'], function () {
            var $ = layui.jquery,
                form = layui.form,
                laydate = layui.laydate,
                table = layui.table,
                commonTable = layui.commonTable,
                common = layui.common;
            //执行一个laydate实例
            laydate.render({
                elem: '#time_horizon'
                , btns: ['clear']
                , trigger: 'click',
                format: 'yyyy/MM/dd',
            });
            var today = new Date();
            today.setTime(today.getTime() - 24 * 60 * 60 * 1000);
            var oYear = today.getFullYear();
            var oMoth = (today.getMonth() + 1).toString();
            if (oMoth.length <= 1) oMoth = '0' + oMoth;
            var oDay = today.getDate().toString();
            if (oDay.length <= 1) oDay = '0' + oDay;
            $('#time_horizon').val(oYear + "/" + oMoth + "/"  + oDay);
            //加载数据
            wcLoading.close();
            //权限控制(js是值传递)
            toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
            commonTable.rendertable({
                elem: '#currentTableId',
                id: 'currentTableId',
                url: '/ReportRecord/CheckDateStorage/GetList',
                filter: {
                    clearFilter: false,
                    //数据量大，data就不需要了
                    items: ['column', 'condition', 'editCondition', 'excel']
                },
                where: { datetime: $('#time_horizon').val(),checktype: 0 },
                cols: [[
                    {
                        field: 'F_CheckStorageType', title: '盘点类型', width: 110, filter: true,
                        templet: function (d) {
                            if (d.F_CheckStorageType==0) {
                                return "库存盘点";
                            }
                            else {
                                return "质检盘点";
                            }
                        }
                    },
                    {
                        field: 'F_CheckDate', title: '日期', width: 160, filter: true
                    },
                    {
                        field: 'F_ClassNum', title: '班次', width: 110, filter: true,
                        templet: function (d) {
                            return top.clients.dataItems["Mes_ClassNumber"][d.F_ClassNum] == null ? "" : top.clients.dataItems["Mes_ClassNumber"][d.F_ClassNum];
                        }
                    },
                    {
                        field: 'F_MaterialType', title: '料号分类', width: 110, filter: true,
                        templet: function (d) {
                            return top.clients.dataItems["Mes_MaterialType"][d.F_MaterialType] == null ? "" : top.clients.dataItems["Mes_MaterialType"][d.F_MaterialType];
                        }
                    },
                    { field: 'F_MaterialCode', title: '料号编号', width: 200, filter: true },
                    { field: 'F_MaterialName', title: '料号名称', width: 200, filter: true },
                    { field: 'F_MaterialUnit', title: '料号单位', width: 120, filter: true },
                    { field: 'F_BeginNum', title: '开班数量', width: 200, filter: true },
                    { field: 'F_CurrentNum', title: '关班数量', width: 200, filter: true },
                    { field: 'F_CurrentPallet', title: '关班托数', width: 200, filter: true },
                    { field: 'F_InNum', title: '入库数量', width: 200, filter: true },
                    { field: 'F_OutNum', title: '出库数量', width: 120, filter: true },
                    { field: 'F_Description', title: '备注', minWidth: 120, filter: true },
                ]]
            });
            //select验证
            form.verify({
                required: function (value, item) {
                    var msg = "必填项不能为空";
                    value = $.trim(value);
                    var isEmpty = !value || value.length < 1;
                    // 当前验证元素是select且为空时,将页面定位至layui渲染的select处，或自定义想定位的位置
                    if (item.tagName == 'SELECT' && isEmpty) {
                        $("html").animate({
                            scrollTop: $(item).siblings(".layui-form-select").offset().top - 74
                        }, 50);
                    }
                    if (isEmpty) {
                        return msg;
                    }
                }
            });
            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                var queryJson = JSON.stringify(data.field);
                //执行搜索重载
                commonTable.reloadtable({
                    elem: 'currentTableId',
                    curr: 1,
                    where: { datetime: data.field.time_horizon, checktype: data.field.checktype, keyword: data.field.txt_keyword }
                });
                return false;
            });

            /**
             * toolbar监听事件
             */
            table.on('toolbar(currentTableFilter)', function (obj) {
                if (obj.event === 'add') {  // 监听删除操作
                    common.modalOpen({
                        title: "清空记录",
                        url: "/ReportRecord/CheckDateStorage/Form",
                        width: "300px",
                        height: "200px",
                    });
                }
                else if (obj.event === 'TABLE_SEARCH') {
                    var _that = $("#searchField");
                    if (_that.hasClass("layui-hide")) {
                        _that.removeClass('layui-hide');
                    } else {
                        _that.addClass('layui-hide');
                    }
                }
                return false;
            });
        });
    </script>

</body>
</html>